package com.leetcode.partition7;

/**
 * @author rkc
 * @date 2022/8/18 9:05
 */
public class LC641设计循环双端队列 {

    private static class MyCircularDeque {

        private static final int N = 3000;
        private int[] q = new int[N];
        private int front = 1500;
        private int last = 1500;
        private int size;

        public MyCircularDeque(int k) {
            size = k;
        }

        public boolean insertFront(int value) {
            if (isFull()) return false;
            q[front--] = value;
            return true;
        }

        public boolean insertLast(int value) {
            if (isFull()) return false;
            q[++last] = value;
            return true;
        }

        public boolean deleteFront() {
            if (isEmpty()) return false;
            front++;
            return true;
        }

        public boolean deleteLast() {
            if (isEmpty()) return false;
            last--;
            return true;
        }

        public int getFront() {
            if (isEmpty()) return -1;
            return q[front + 1];
        }

        public int getRear() {
            if (isEmpty()) return -1;
            return q[last];
        }

        public boolean isEmpty() {
            return front == last;
        }

        public boolean isFull() {
            return last - front == size;
        }
    }
}
